import ModalFactory from './factory.js'

(() => {
    const oModal = document.getElementsByClassName('modal')[0];
    const oBtnGroup = document.getElementsByClassName('btn-group')[0];
    const modalFactory = new ModalFactory(oModal);

    const init = () => {
        bindEvent();
    };

    function bindEvent() {
        oBtnGroup.addEventListener('click', handleBtnClick, false);
    }

    function handleBtnClick(e) {
        const tar = e.target,
            tagName = tar.tagName;

        if (tagName === 'BUTTON') {
            const status = tar.dataset.status;

            const modal = modalFactory.create('这是工厂模式', status);
            // 返回的函数是拓展出来的功能
            switch (status) {
                case 'W':
                    modal.outputInfo('告警提示')
                    break;
                case 'E':
                    modal.outputInfo('错误提示')
                    break;
                case 'S':
                    modal.goHome('https://www.baidu.com/');
                    break;
                default:
                    break;
            }
        }
    }

    init();
})();